home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTDRIVER / DTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  7.5 KB  |  263 lines

  1. /*** dtest.c
  2.  *
  3.  *  DTEST.TTP  -- Disk/DMA test program
  4.  *    gcc {-DVERBOSE} -o dtest.ttp dtest.c -liio
  5.  *
  6.  *  910315 JWTittsler    originally a wrapper for TT DMA test program
  7.  *  910325 jwt    make the GetBPB() call only if given the -B switch
  8.  *        show only first 10 errors/cycle, unless given -E switch
  9.  *  910326 jwt    make clearing the buffers optional, setable fill value
  10.  *        -L sets limit from base record; if set then -I specifies
  11.  *          increment from one cycle to next, if I==0 then random
  12.  *          blocks
  13.  */
  14.  
  15. #define VERSION "  Version of May 07 15:46:00 PST 1991"
  16.  
  17. #define OPTIONS "bBc:C:d:D:eEfFi:I:l:L:o:O:p:P:r:R:s:S:Zz"
  18. #define    RECORDSIZE    (512L)
  19. #define SLOP        (8L)    /* space between buffers (in bytes) */
  20. #define    SHOWABLEERRORS    (10L)    /* default number of errors to show per pass */
  21.  
  22. /* BIOS Definitions */
  23. /* Bconxx() handles */
  24. #define    CONSOLE        2
  25.  
  26. /* Rwabs() flags */
  27. #define    READ        (0)
  28. #define WRITE        (1)
  29. #define    PHYSICAL    (8)
  30. #define    PHYSREAD    (READ+PHYSICAL)
  31. #define    PHYSWRITE    (WRITE+PHYSICAL)
  32.  
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <osbind.h>
  36. #include <ctype.h>
  37. #include <unixlib.h>
  38. #include <string.h>
  39.  
  40. extern int opterr,optind;
  41. extern char *optarg;
  42.  
  43. long lErrors=0L;
  44. int bAllErrors=0;
  45. int bGenerateFill=0;
  46.  
  47. void Usage(void){
  48.     puts("DTEST -B -E -F -Z -G -C nnnn -D nn -I nnnn \
  49. -L nnnn -O n -P nnn -R nnnn");
  50.     puts("  where:");
  51.     puts("   -B       do getbpb() call");
  52.     puts("   -E       show all errors {first 10/cycle}");
  53.     puts("   -F       put buffer in Fast RAM");
  54.     puts("   -Z       don't preset read buffers");
  55.     puts("   -G       generate fill pattern {0s}");
  56.     puts("   -C nnnn  record count {3072}");
  57.     puts("   -D nn    TOS physical device number {0}");
  58.     puts("   -W nnnn  number of writes before each read/compare {100}");
  59.     puts("   -I nnnn  increment {0, random if limit specified}");
  60.     puts("   -L nnnn  limit to be added to base record number {0}");
  61.     puts("   -O n     offset from long alignment {0}");
  62.     puts("   -P nnn   read buffer preset value {0}");
  63.     puts("   -R nnnn  base starting record number {274000}");
  64. }
  65.  
  66. int GetNumArg(char *string){
  67.     return(atoi(string));    /* someday this will handle hex and decimal */
  68. }                /*  yeah, sure */
  69.  
  70. long GetLongArg(char *string){
  71.     return(atol(string));    /* someday this will handle hex and decimal */
  72. }                /*  yeah, sure */
  73.  
  74. char *Myalloc(long size, short type){
  75. int nTOSVersion, nTemp;
  76.     nTemp = Sversion();
  77.     nTOSVersion = (nTemp>>8) | ((nTemp&0xFF)<<8);    /* byte swap */
  78.     if (nTOSVersion >= 0x0019) return (char *)Mxalloc(size, type);
  79.     else if (type) return NULL;    /* old TOS only has one kind of RAM */
  80.     else return (char *)Malloc(size);
  81. }
  82.  
  83. void SetBuffer(unsigned char *pB, long lBufferSize, int nPass) {
  84. register int i;
  85. register unsigned char bVal;
  86. register unsigned long bLval;
  87. unsigned long *lB;
  88. register long j;
  89.  
  90.     if (bGenerateFill) {
  91.         bVal = (unsigned char) nPass;
  92.         for(i=0; i<lBufferSize; ++i){
  93.         *pB++ = bVal++;
  94.         }
  95.         /*
  96.         memcpy(pB, "\0x11\0x22\0x33\0x44\0x55\0x66\0x77\0x88", 8);
  97.         /**/
  98.     } else {
  99.         j = lBufferSize >> 2;
  100.         lB = (unsigned long *)pB;
  101.         for(i=0; i<j; ++i){
  102.         *lB++ = 0L;
  103.         }
  104.     }
  105. }
  106.  
  107. int CompareBuffers(register unsigned char *p1, register unsigned char *p2,
  108.     register long lBSize){
  109. register long i;
  110. register unsigned char c1,c2;
  111. unsigned char *wbuf;
  112. long lErrorsThisCycle=0L;
  113.  
  114.     wbuf = p1;
  115.     for(i=0; i<lBSize; ++i) {
  116.         c1 = *p1++;  c2 = *p2++;
  117.         if(c1 != c2) {
  118.         ++lErrors;
  119.         ++lErrorsThisCycle;
  120.         --p1;
  121.         if((lErrorsThisCycle <= SHOWABLEERRORS)||(bAllErrors))
  122.             printf("\nError @ wbuf 0x%08X (offset 0x%06X) \
  123. Wr: %s0x%02X\033q Rd: %s0x%02X\033q",
  124.             (long)(p1), (long)(p1-wbuf),
  125.             (c1==c2) ? "\033p" : "", c1,
  126.             (c2==c1) ? "\033p" : "", c2);
  127.         ++p1;
  128.         if(Cconis() != 0) break;
  129.         }
  130.     }
  131.     if(lErrorsThisCycle) printf("\nErrors this cycle: %ld",
  132.         lErrorsThisCycle);
  133.     return (int)(lErrorsThisCycle != 0);
  134. }
  135.  
  136. void main(int argc, const char *argv[]){
  137. int option;
  138. int nOffset=0, nDevice=10, nCount=3072;
  139. long nRecord=274000L, nBaseRecord=274000L;
  140. int nLimit=0, nIncrement=0;
  141. int bFastRAM=0, bDoGetBPB=0, bDoBufferFill=1;
  142. unsigned char *pBuffer,*pBuf1,*pBuf2,cSeed=0;
  143. long lBufferSize;
  144. long lErrx;
  145. int bHadError;
  146. int nPass;
  147. int nResult;
  148. int i;
  149.  
  150.     puts("Disk R/W Through Lrwabs()");
  151.     puts(VERSION);
  152.  
  153.     while((option=getopt(argc, argv, OPTIONS)) != EOF)
  154.         switch (toupper(option)) {
  155.         case 'B':  bDoGetBPB=1; break;
  156.         case 'E':  bAllErrors=1; break;
  157.         case 'F':  bFastRAM=1; break;
  158.         case 'Z':  bDoBufferFill=0; break;
  159.         case 'C':  nCount = GetNumArg(optarg); break;
  160.         case 'D':  nDevice = GetNumArg(optarg); break;
  161.         case 'I':  nIncrement = GetNumArg(optarg); break;
  162.         case 'L':  nLimit = GetNumArg(optarg); break;
  163.         case 'O':  nOffset = GetNumArg(optarg); break;
  164.         case 'P':  cSeed = (unsigned char)GetNumArg(optarg); break;
  165.         case 'R':  nRecord = nBaseRecord = GetLongArg(optarg); break;
  166.         case 'G':  bGenerateFill=1; break;
  167.         default:   Usage(); exit(1);
  168.         }
  169.  
  170.     lBufferSize = (long)nCount*RECORDSIZE;
  171.  
  172.     if((pBuffer=(unsigned char *)Myalloc(2L*(lBufferSize+SLOP)+10L,
  173.         bFastRAM))==NULL){
  174.         printf("Unable to allocate transfer buffers\n");
  175.         exit(2);
  176.     }
  177.  
  178.     pBuf1 = pBuffer;
  179.  
  180.     /* Ensure buffers are all long word boundary */
  181.     if ((long)pBuf1 % 4) {
  182.         pBuf1 += 2;
  183.     }
  184.  
  185.     pBuf2 = pBuf1+lBufferSize+SLOP;
  186.  
  187. #ifdef VERBOSE
  188.     printf("Buffer size:  %08X\n", (long)lBufferSize);
  189.     printf("    Buffer1:  %08X\n", (long)pBuf1);
  190.     printf("    Buffer2:  %08X\n", (long)pBuf2);
  191.     printf("     Offset:  %d\n", nOffset);
  192.     printf("     Device:  %d\n", nDevice);
  193.     printf("     Record:  %ld\n", nRecord);
  194.     if (nLimit) {
  195.         printf("      Limit:  %d\n", nLimit);
  196.         if(nIncrement) printf("  Increment:  %d\n", nIncrement);
  197.         else printf("  Increment:  Random\n");
  198.     }
  199.     printf("      Count:  %d\n", nCount);
  200. #endif /* VERBOSE */
  201.  
  202.     printf("Are you SURE you want to trash media in TOS unit %d? ",
  203.         nDevice);
  204.     fflush(stdout);
  205.     gets((char *)pBuf1);
  206.  
  207.     if(toupper(*pBuf1) != 'Y') exit(1);
  208.  
  209.     if(bDoGetBPB) Getbpb(nDevice);        /* clear media change errors */
  210.  
  211.     nPass = 0;
  212.  
  213.     while(Cconis()==0){
  214.         ++nPass;
  215.         bHadError = 0;
  216.         printf("\rCycle: %6d  Record: %6ld  Errors: %6ld  ", 
  217.         nPass, nBaseRecord, lErrors);
  218.         fflush(stdout);
  219.  
  220.         /* write a known pattern to the disk */
  221.         SetBuffer(pBuf1, lBufferSize, nPass);
  222.         putchar('W');  fflush(stdout);
  223.         if(nResult=Lrwabs(PHYSWRITE, pBuf1, nCount, nRecord, nDevice)){
  224.             printf("%02X", nResult);
  225.             ++lErrors;
  226.             bHadError = 1;
  227.         }
  228.  
  229.         /* now preset the destination buffers */
  230.         if(bDoBufferFill){
  231.             memset(pBuf2, cSeed, lBufferSize);
  232.         }
  233.  
  234.         /* read it in once */
  235.         putchar('R');  fflush(stdout);
  236.         if(nResult=Lrwabs(PHYSREAD, pBuf2, nCount, nRecord, nDevice)){
  237.             printf("%02X", nResult);
  238.         ++lErrors;
  239.         bHadError = 1;
  240.         }
  241.  
  242.         /* now compare the read to the original */
  243.         putchar('C');  fflush(stdout);
  244.         bHadError += CompareBuffers(pBuf1, pBuf2, lBufferSize);
  245.  
  246.         putchar(bHadError ? '\n' : '.');
  247.         fflush(stdout);
  248.  
  249.         /* set up a new starting record for the next cycle */
  250.         if(nLimit){        /* is starting record allowed to change? */
  251.         if(nIncrement){    /* a linear increment */
  252.             if((nRecord += nIncrement) > (nBaseRecord+nLimit))
  253.                 nRecord = nBaseRecord;
  254.         } else {     /* a random distance up to limit away */
  255.             nRecord = nBaseRecord + (Random()%(long)nLimit);
  256.         }
  257.         }
  258.  
  259.     }
  260.  
  261.     (void)Cconin();        /* swallow up character */
  262. }
  263.